// pages/calendar/calendar.js
const util = require('../../utils/util.js')
import baseuser from '~/utils/users.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        settop: 0,
        minday: '1693497600000',
        maxday: '1696089600000',
        mire: 1694707200000,
        mymonth: 1,
        mydatas: 1,
        formatter(day) {
            const date = day.date.getDate();
            const currentDate = new Date();
            const days = currentDate.getDate();
            if (date === 16) {
            } else if (date === 27) {
                day.bottomInfo = '•';
            } else if (date === days) {
                day.text = '今天';
            }
            return day;
        },


        pages:1,
        indexlist:[],
    },
    naveback() {
        wx.navigateBack()
    },
    nextdetail(e) {
        wx.navigateTo({
            url: `../details/details?id=${e.currentTarget.dataset.id}`,
        })
    },
    async gatdaylist() {
        let reqdata = {
            "time": this.data.mydatas,
            "current": this.data.pages,
            "pageSize": "10"
        }
        let resdata = await baseuser.selectByDay(reqdata)
        console.log(resdata)
        if (resdata.code == 200) {
            this.setData({
                indexlist: resdata.data.result.records
            })
        } else {
            wx.showToast({
                title: '查询失败',
                icon: 'none',
                duration: 2000
            })
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let Bartop = (0, wx.getMenuButtonBoundingClientRect)().top;
        let BarHeight = (0, wx.getMenuButtonBoundingClientRect)().height;

        console.log(wx.getMenuButtonBoundingClientRect())
        this.setData({
            settop: Bartop + BarHeight * 1.5
        })
        // 获取当前日期
        const currentDate = new Date();
        const mymonth = currentDate.getMonth() + 1;
        const year = currentDate.getFullYear();
        const month = (currentDate.getMonth() + 1).toString().padStart(2, "0");
        const day = currentDate.getDate().toString().padStart(2, "0");

        const today = `${year}-${month}-${day}`;
        // 获取当月第一天日期
        const firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
        const firstDayTimestamp = firstDayOfMonth.getTime();

        // 获取当月最后一天日期
        const lastDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
        const lastDayTimestamp = lastDayOfMonth.getTime();

        console.log(firstDayTimestamp);
        console.log(lastDayTimestamp);
        this.setData({
            mydatas: today,
            mymonth: mymonth,
            minday: firstDayTimestamp,
            maxday: lastDayTimestamp,
        })
        setTimeout(() => {
            this.setData({
                formatter(day) {
                    const date = day.date.getDate();
                    const currentDate = new Date();
                    const days = currentDate.getDate();

                    if (date == 10) {
                        day.bottomInfo = '•';
                    }
                    if (date === 16) {
                    } else if (date === 20) {
                        day.bottomInfo = '•';
                    } else if (date === days) {
                        day.text = '今天';
                    }
                    return day;
                },
            })
        }, 10000);
        this.gatdaylist()
    },
    dataselect(items) {
        const date = new Date(items.detail);
        const year = date.getFullYear();
        const month = (date.getMonth() + 1).toString().padStart(2, "0");
        const day = date.getDate().toString().padStart(2, "0");
        const formattedDate = `${year}-${month}-${day}`;

        this.setData({
            mydatas: formattedDate,
        })
        this.gatdaylist()
    },
    backmyday() {
        const currentDate = Date.now()
        this.selectComponent('#calendar').setData({currentDate:currentDate})
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})